import { defineStore } from 'pinia'
import { store } from '../index'
import { useStorage } from '@/hooks/web/useStorage'
import router from '@/router'
const { getStorage, setStorage } = useStorage()

interface AppState {
  userInfo: any
  pageData: any
  searchForm: any
}

export const useAppStore = defineStore('app', {
  state: (): AppState => {
    return {
      userInfo: {}, // 用户信息存储
      pageData: {},
      searchForm: {}
    }
  },
  getters: {
    getUserInfo(): any {
      return this.userInfo
    },
    getSearchForm(): any {
      return this.searchForm
    }
  },
  actions: {
    setUserInfo(userInfo: any) {
      console.log(userInfo)
      this.userInfo = userInfo
      setStorage('userInfo', userInfo)
    },
    setPageData(name: string, data: any): any {
      this.pageData[name] = data
    },
    getPageData(name: string): any {
      return this.pageData[name]
    },
    setSearchForm(data: any): any {
      this.searchForm = data
    }
  }
})

export const useAppStoreWithOut = () => {
  return useAppStore(store)
}
